package com.tianhui.consignortwofei.mvp.ui.adapter;

import android.content.Context;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.fgs.common.utils.StringUtil;
import com.fgs.common.widget.itemView.DetailItemView;
import com.tianhui.consignortwofei.R;
import com.tianhui.consignortwofei.mvp.model.enty.DriverInfo;

import org.yczbj.ycrefreshviewlib.adapter.RecyclerArrayAdapter;
import org.yczbj.ycrefreshviewlib.holder.BaseViewHolder;

/**
 * @author fgs
 * @date 2020/8/27
 * @description
 **/
public class DriverListAdapter extends RecyclerArrayAdapter<DriverInfo> {

    public DriverListAdapter(Context context) {
        super(context);
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new OrderListViewHolder(parent, R.layout.item_driver_list);
    }

    private class OrderListViewHolder extends BaseViewHolder<DriverInfo> {

        private TextView orderNumberTextView;
        private TextView orderStatusTextView;
        private DetailItemView oneDetailItemView;
        private DetailItemView twoDetailItemView;
        private DetailItemView threeDetailItemView;
        private DetailItemView fourDetailItemView;
        private DetailItemView fiveDetailItemView;
        private DetailItemView timeDetailItemView;
        private Button auditButton;
        private Button carrierButton;
        private Button remarkButton;


        public OrderListViewHolder(ViewGroup parent, int res) {
            super(parent, res);
            orderNumberTextView = getView(R.id.item_driver_list_topLeftTextView);
            orderStatusTextView = getView(R.id.item_driver_list_topRightTextView);

            oneDetailItemView = getView(R.id.item_driver_list_oneDetailItemView);
            twoDetailItemView = getView(R.id.item_driver_list_twoDetailItemView);
            threeDetailItemView = getView(R.id.item_drvier_list_threeDetailItemView);
            fourDetailItemView = getView(R.id.item_driver_list_fourDetailItemView);
            fiveDetailItemView = getView(R.id.item_driver_list_fiveDetailItemView);
            timeDetailItemView = getView(R.id.item_driver_list_timeDetailItemView);
            auditButton = getView(R.id.item_driver_list_auditButton);
            carrierButton = getView(R.id.item_driver_list_carrierButton);
            addOnClickListener(R.id.item_driver_list_operateButton);
            addOnClickListener(R.id.item_driver_list_editButton);
            addOnClickListener(R.id.item_driver_list_auditButton);
            addOnClickListener(R.id.item_driver_list_carrierButton);
            addOnClickListener(R.id.item_driver_list_remarkButton);
            addOnClickListener(R.id.item_driver_list_viewPasswordButton);

            //修改手机号
            addOnClickListener(R.id.item_driver_list_changPhone);
            //删除司机
            addOnClickListener(R.id.item_driver_list_delete);
        }

        @Override
        public void setData(DriverInfo data) {
            super.setData(data);
            //司机姓名
            orderNumberTextView.setText("司机姓名：" + data.drivername);
            //司机电话
            oneDetailItemView.setTitle("司机电话：");
            oneDetailItemView.setContent(data.drivertel);
            //身份证
            twoDetailItemView.setTitle("身份证号：");
            if (!TextUtils.isEmpty(data.driveridcard)) {
                twoDetailItemView.setContent(data.driveridcard + "(" + data.idcardcount + ")");
            }
            //默认车辆
            threeDetailItemView.setTitle("默认车辆：");
            threeDetailItemView.setContent(data.defaultvehiclenum);
            //准驾类型
            fourDetailItemView.setTitle("准驾类型：");
            fourDetailItemView.setContent(data.transporttypename);
            //创建时间
            timeDetailItemView.setTitle("创建时间：");
            timeDetailItemView.setContent(data.create_time);
            //状态
            orderStatusTextView.setText(Html.fromHtml(getAuthStatus(data)));

            if (data.isaudit == 1) {
                auditButton.setVisibility(View.GONE);
            } else {
                auditButton.setVisibility(View.VISIBLE);
            }

            if (!TextUtils.isEmpty(data.idcardcount) && StringUtil.compareTwoString(data.idcardcount, "1") > 0) {
                carrierButton.setVisibility(View.VISIBLE);
            } else {
                carrierButton.setVisibility(View.GONE);
            }

            fourDetailItemView.setTitle("所属承运商：");
            if (!TextUtils.isEmpty(data.carriername)) {
                fourDetailItemView.setContent(data.carriername);
            } else {
                fourDetailItemView.setContent("个人");
            }
            fiveDetailItemView.setTitle("备注：");
            fiveDetailItemView.setContent(data.remarks);

        }
    }

    private String getAuthStatus(DriverInfo info) {

        String status = "状态：<font color='#f52225'>" + "未审核" + "</font>";
        if (info == null) {
            return status;
        }
        if (info.isaudit == 0) {
            status = "状态：<font color='#f52225'>" + "未审核" + "</font>";
        } else if (info.isaudit == 1) {
            status = "状态：<font color='#008000'>" + "已审核" + "</font>";
        } else if (info.isaudit == 2) {
            status = "状态：<font color='#0000FF'>" + "待审核" + "</font>";
        }
        return status;

    }
}
